<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/hexo_blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo_blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo_blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo_blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo_blog/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.css">
  <script src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"bone-nails.gitee.io","root":"/hexo_blog/","images":"/hexo_blog/images","scheme":"Gemini","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/hexo_blog/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":true}};
  </script>
<meta name="description" content="持续更新中 利用Ant打jar包">
<meta property="og:type" content="article">
<meta property="og:title" content="Maven大型攻略">
<meta property="og:url" content="https://bone-nails.gitee.io/2021/04/01/Maven%E5%A4%A7%E5%9E%8B%E6%94%BB%E7%95%A5/index.html">
<meta property="og:site_name" content="Carson Zhao">
<meta property="og:description" content="持续更新中 利用Ant打jar包">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzE4LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzE5LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIwLlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIxLlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIyLlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIzLlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI0LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI1LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI2LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI3LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI4LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI5LlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzMwLlBORw?x-oss-process=image/format,png">
<meta property="og:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzMxLlBORw?x-oss-process=image/format,png">
<meta property="article:published_time" content="2021-04-01T04:23:20.000Z">
<meta property="article:modified_time" content="2021-04-01T04:21:21.553Z">
<meta property="article:author" content="Carson Zhao">
<meta property="article:tag" content="Maven">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzE4LlBORw?x-oss-process=image/format,png">


<link rel="canonical" href="https://bone-nails.gitee.io/2021/04/01/Maven%E5%A4%A7%E5%9E%8B%E6%94%BB%E7%95%A5/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>Maven大型攻略 | Carson Zhao</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/hexo_blog/atom.xml" title="Carson Zhao" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo_blog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">Carson Zhao</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/hexo_blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-about"><a href="/hexo_blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
        <li class="menu-item menu-item-tags"><a href="/hexo_blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
        <li class="menu-item menu-item-categories"><a href="/hexo_blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%8C%81%E7%BB%AD%E6%9B%B4%E6%96%B0%E4%B8%AD"><span class="nav-number">1.</span> <span class="nav-text">持续更新中</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%A9%E7%94%A8Ant%E6%89%93jar%E5%8C%85"><span class="nav-number"></span> <span class="nav-text">利用Ant打jar包</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Maven"><span class="nav-number"></span> <span class="nav-text">Maven</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%93%E5%BA%93%E5%88%86%E7%B1%BB%EF%BC%9A"><span class="nav-number"></span> <span class="nav-text">仓库分类：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E5%94%AF%E4%B8%80%E7%A1%AE%E5%AE%9A%E4%B8%80%E4%B8%AAjar%E5%8C%85%EF%BC%9F"><span class="nav-number"></span> <span class="nav-text">如何唯一确定一个jar包？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E7%94%A8IDEA%E6%9E%84%E5%BB%BAMaven%E5%B7%A5%E7%A8%8B"><span class="nav-number"></span> <span class="nav-text">如何用IDEA构建Maven工程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#pom-xml%E8%AF%A6%E8%A7%A3"><span class="nav-number"></span> <span class="nav-text">pom.xml详解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#maven%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%EF%BC%88%E5%9C%A8Terminal%E8%BE%93%E5%85%A5%EF%BC%89"><span class="nav-number"></span> <span class="nav-text">maven常用命令（在Terminal输入）</span></a></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Carson Zhao"
      src="/hexo_blog/images/1.png">
  <p class="site-author-name" itemprop="name">Carson Zhao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo_blog/archives">
          <span class="site-state-item-count">59</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo_blog/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo_blog/tags/">
          
        <span class="site-state-item-count">35</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="cc-license site-overview-item animated" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/hexo_blog/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://bone-nails.gitee.io/2021/04/01/Maven%E5%A4%A7%E5%9E%8B%E6%94%BB%E7%95%A5/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo_blog/images/1.png">
      <meta itemprop="name" content="Carson Zhao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Carson Zhao">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Maven大型攻略
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2021-04-01 12:23:20 / 修改时间：12:21:21" itemprop="dateCreated datePublished" datetime="2021-04-01T12:23:20+08:00">2021-04-01</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/hexo_blog/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.9k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>3 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h3 id="持续更新中"><a href="#持续更新中" class="headerlink" title="持续更新中"></a>持续更新中</h3><span id="more"></span>
<h2 id="利用Ant打jar包"><a href="#利用Ant打jar包" class="headerlink" title="利用Ant打jar包"></a>利用Ant打jar包</h2><ul>
<li>Ant：eclipse工具在项目编译运行时依赖Ant这个构建工具。</li>
<li>适用场景：<br>在使用Eclipse进行团队开发时，经常会使用到别人的代码，此时就需要将别人项目打包成的jar包引入到我们的项目中，以便于使用别人的类和方法。</li>
<li>如何打jar包</li>
</ul>
<ol>
<li>假设现在我的Eclipse中有两个项目Test1和Test2（如图），Test1中需要使用Test2中的show2方法，这时我们就是用Ant将Test2进行打包。<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzE4LlBORw?x-oss-process=image/format,png"></li>
<li>现在我们右键Test2项目–Export–Java–JAR file–选择Jar包存放路径(我放到了桌面)点击finish即可。<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzE5LlBORw?x-oss-process=image/format,png"></li>
<li>将桌面上的Test2.jar复制粘贴到Test1项目中，再右击Test.jar，选择Build Path–Add To Build Path，此时再导入Test2包就可以调用Test2了，如图：<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIwLlBORw?x-oss-process=image/format,png"><br><code>Ant的缺陷：对于以来的管理不够智能，jar包的更新不能实现实时同步。</code></li>
</ol>
<h1 id="Maven"><a href="#Maven" class="headerlink" title="Maven"></a>Maven</h1><ul>
<li>基于Ant的构建工具，弥补了Ant的缺陷。</li>
<li>对比：<br>Ant需要手动引入jar文件到项目<br>Maven构建的项目依赖第三方jar包，不需要手动引入，找仓库要即可。<h2 id="仓库分类："><a href="#仓库分类：" class="headerlink" title="仓库分类："></a>仓库分类：</h2>Maven本地仓库：自己文件系统的一个文件夹，可自己设置路径。<br>Maven远程仓库：一个URL路径。<br>国外仓库地址：<a target="_blank" rel="noopener" href="https://repo1.maven.org/maven2/">https://repo1.maven.org/maven2/</a><br>国内阿里云仓库：<a target="_blank" rel="noopener" href="https://maven.aliyun.com/mvn/view">https://maven.aliyun.com/mvn/view</a><blockquote>
<p>优先从本地仓库寻找依赖，找不到再从远程仓库寻找。<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIxLlBORw?x-oss-process=image/format,png"></p>
</blockquote>
<h2 id="如何唯一确定一个jar包？"><a href="#如何唯一确定一个jar包？" class="headerlink" title="如何唯一确定一个jar包？"></a>如何唯一确定一个jar包？</h2>通过maven仓库中jar包的三个重要坐标：</li>
</ul>
<ol>
<li>Group Id 公司或组织名</li>
<li>Aritifact Id 项目名</li>
<li>version  版本 （默认0.0.1.SNAOSHOT快照版本，项目发布改为0.0.1.RELEASE稳定版本）  <h2 id="如何用IDEA构建Maven工程"><a href="#如何用IDEA构建Maven工程" class="headerlink" title="如何用IDEA构建Maven工程"></a>如何用IDEA构建Maven工程</h2></li>
<li>下载<a target="_blank" rel="noopener" href="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com/%E5%B7%A5%E5%85%B7%E5%BA%93/apache-maven-3.6.0.zip">Maven</a>，官网下载地址：<a target="_blank" rel="noopener" href="https://maven.apache.org/">ttps://maven.apache.org/</a>,解压到随便一个不到中文的路径，再配置环境变量MAVEN_HOME<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIyLlBORw?x-oss-process=image/format,png"><br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzIzLlBORw?x-oss-process=image/format,png"><br><code>%MAVEN_HOME%表示到系统变量中取MAVEN_HOME的值</code><br><code> 终端测试：mvn -version</code></li>
<li>修改Maven核心配置文件conf/settings.xml—-添加本地仓库路径</li>
</ol>
<ul>
<li>ctrl+f搜索localhostRepository：<br>修改内容如下：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;localRepository&gt;D:\apache-maven-3.6.0\repository&lt;&#x2F;localRepository&gt;</span><br></pre></td></tr></table></figure>
<code>这里我直接在D盘maven安装目录下新建了一个repository目录作为本地仓库。</code></li>
</ul>
<ol start="3">
<li>修改Maven核心配置文件conf/settings.xml—-添加远程仓库路径<br>在<mirrors>标签内添加如下内容:  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">  &lt;mirror&gt;</span><br><span class="line">&lt;id&gt;alimaven&lt;&#x2F;id&gt;</span><br><span class="line">&lt;name&gt;aliyun maven&lt;&#x2F;name&gt;</span><br><span class="line">&lt;url&gt;http:&#x2F;&#x2F;maven.aliyun.com&#x2F;nexus&#x2F;content&#x2F;groups&#x2F;public&#x2F;&lt;&#x2F;url&gt;</span><br><span class="line">&lt;mirrorOf&gt;central&lt;&#x2F;mirrorOf&gt;</span><br><span class="line"> &lt;&#x2F;mirror&gt;</span><br></pre></td></tr></table></figure></li>
<li>修改Maven核心配置文件conf/settings.xml—-配置JDK版本（默认1.4）<br>ctrl+f搜索jdk，在<profiles>标签下添加如下：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">   &lt;profile&gt;  </span><br><span class="line">    &lt;id&gt;jdk-1.8&lt;&#x2F;id&gt;  </span><br><span class="line">    &lt;activation&gt;  </span><br><span class="line">        &lt;activeByDefault&gt;true&lt;&#x2F;activeByDefault&gt;  </span><br><span class="line">        &lt;jdk&gt;1.8&lt;&#x2F;jdk&gt;  </span><br><span class="line">    &lt;&#x2F;activation&gt;</span><br><span class="line">    &lt;properties&gt;</span><br><span class="line">        &lt;project.build.sourceEncoding&gt;UTF-8&lt;&#x2F;project.build.sourceEncoding&gt;</span><br><span class="line">        &lt;maven.compiler.source&gt;1.8&lt;&#x2F;maven.compiler.source&gt;  </span><br><span class="line">        &lt;maven.compiler.target&gt;1.8&lt;&#x2F;maven.compiler.target&gt;   </span><br><span class="line">    &lt;&#x2F;properties&gt;   </span><br><span class="line">&lt;&#x2F;profile&gt;</span><br></pre></td></tr></table></figure></li>
<li>IDEA配置Maven工程</li>
</ol>
<ul>
<li>File-Other Settings-Settings for New Projects-Maven，修改内容如下：<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI0LlBORw?x-oss-process=image/format,png"></li>
<li>创建Maven工程：File-new-Project-左侧选择Maven<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI1LlBORw?x-oss-process=image/format,png"></li>
<li>输入坐标信息：<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI2LlBORw?x-oss-process=image/format,png"></li>
<li>勾选左下角的,自动引入第三方依赖<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI3LlBORw?x-oss-process=image/format,png"></li>
</ul>
<ol start="6">
<li>已知创建了Test1和Test2两个Maven项目，并且在Test2中随便写了一个方法，如何将Test2打成jar包呢？</li>
</ol>
<ul>
<li>Terminal输入<code>mvn install</code>即可：<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI4LlBORw?x-oss-process=image/format,png"></li>
<li>此时就能在本地仓库找到刚刚打包好的jar包<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzI5LlBORw?x-oss-process=image/format,png"></li>
</ul>
<ol start="7">
<li>如何在Test1中引入Test2的jar包？</li>
</ol>
<ul>
<li>在Test1的pom.xml中添加Test2的坐标即可。如图：<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzMwLlBORw?x-oss-process=image/format,png"><br><code>如果有红色错误，建议去settings-maven和other settings-maven看看仓库地址是否配置正确。</code></li>
</ul>
<ol start="8">
<li>此时就可以在test1里面使用Test2的方法，Test2的jar包存放在本地仓库，使用时在本地仓库寻找即可，就不需要Eclipse+Ant那样的繁琐操作了。<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly96emotMTMwMDQwODQ5My5jb3MuYXAtY2hlbmdkdS5teXFjbG91ZC5jb20vJUU1JTlCJUJFJUU1JUJBJThBLzMxLlBORw?x-oss-process=image/format,png"></li>
<li>Maven的强大之处：<br>自动管理依赖：<br>当Test2更新之后，不需要想Eclipse一样重新打jar包，重新引入，只需要在Test2的Terminal重新执行mvn install命令即可实现更新。</li>
</ol>
<h2 id="pom-xml详解"><a href="#pom-xml详解" class="headerlink" title="pom.xml详解"></a>pom.xml详解</h2><p>project object model 项目对象模型<br>打包类型：<br><code>&lt;packaging&gt;&lt;/packaging&gt;</code><br>三种取值：jar，war，pom<br>jar：表示普通java工程，写模块给别人调用<br>war：Java Web工程：可以运行在tomcat里面的web工程<br>pom：申明一个父工程，让子工程去继承，继承后就能得到父工程里面的依赖和版本。</p>
<h2 id="maven常用命令（在Terminal输入）"><a href="#maven常用命令（在Terminal输入）" class="headerlink" title="maven常用命令（在Terminal输入）"></a>maven常用命令（在Terminal输入）</h2><table>
<thead>
<tr>
<th>指令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>mvn install</td>
<td>安装项目到本地仓库</td>
</tr>
<tr>
<td>mvn clean</td>
<td>清除target目录（缓存）</td>
</tr>
<tr>
<td>mvn compile</td>
<td>编译项目（将java代码编译到target目录）</td>
</tr>
<tr>
<td>mvn test</td>
<td>运行所有的测试用例</td>
</tr>
<tr>
<td>mvn deploy</td>
<td>部署项目到服务器</td>
</tr>
<tr>
<td>mvn package</td>
<td>打包项目，由pom.xml中的packaging确定打包类型，打完的包在target下</td>
</tr>
</tbody></table>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Carson Zhao
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://bone-nails.gitee.io/2021/04/01/Maven%E5%A4%A7%E5%9E%8B%E6%94%BB%E7%95%A5/" title="Maven大型攻略">https://bone-nails.gitee.io/2021/04/01/Maven大型攻略/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/hexo_blog/tags/Maven/" rel="tag"># Maven</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/hexo_blog/2021/04/01/ping%E4%B8%8D%E9%80%9Aip%E5%9C%B0%E5%9D%80-%E5%A4%96%E7%BD%91%E7%9A%84%E5%8E%9F%E5%9B%A0/" rel="prev" title="ping不通ip地址/外网的原因">
                  <i class="fa fa-chevron-left"></i> ping不通ip地址/外网的原因
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/hexo_blog/2021/04/01/markdown%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95/" rel="next" title="markdown基本语法">
                  markdown基本语法 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Carson Zhao</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">125k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">1:54</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script size="300" alpha="0.6" zIndex="-1" src="https://cdn.jsdelivr.net/npm/ribbon.js@1.0.2/dist/ribbon.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/hexo_blog/js/utils.js"></script><script src="/hexo_blog/js/next-boot.js"></script>

  
<script src="/hexo_blog/js/local-search.js"></script>



<script>
if (document.querySelectorAll('.pdf-container').length) {
  NexT.utils.getScript('https://cdn.jsdelivr.net/npm/pdfobject@2.2.4/pdfobject.min.js', () => {
    document.querySelectorAll('.pdf-container').forEach(element => {
      PDFObject.embed(element.dataset.target, element, {
        pdfOpenParams: {
          navpanes : 0,
          toolbar  : 0,
          statusbar: 0,
          pagemode : 'thumbs',
          view     : 'FitH'
        },
        PDFJS_URL: '/hexo_blog/lib/pdf/web/viewer.html',
        height   : element.dataset.height
      });
    });
  }, window.PDFObject);
}
</script>


  <script>
    NProgress.configure({
      showSpinner: true
    });
    NProgress.start();
    document.addEventListener('readystatechange', () => {
      if (document.readyState === 'interactive') {
        NProgress.inc(0.8);
      }
      if (document.readyState === 'complete') {
        NProgress.done();
      }
    });
    document.addEventListener('pjax:send', () => {
      NProgress.start();
    });
    document.addEventListener('pjax:success', () => {
      NProgress.done();
    });
  </script>

  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





<script src="/hexo_blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/hexo_blog/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":200,"height":400},"mobile":{"show":true},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
